<template>
	<view class="home-box">
		<!-- 搜索 -->
		<mysearch></mysearch>
		<!-- 内容-->
		<view class="content-box">
			<!-- 分类 -->
			<view class="icon-box">
				<view @click="toCateShop(item)" class="icon-item" v-for="item in categoryList" :key="item.shopId">
					<view class="img-box">
						<image :src="item.picture" class="img"></image>
					</view>
					<text class="category">{{item.name}}</text>
				</view>
			</view>
			<!-- 公告 -->
			<view class="notice-box">
				<u-notice-bar :text="text" speed="100" icon="" url="" color="black" bgColor="#F8F8F8" class="notice"></u-notice-bar>
			</view>
			<!-- 轮播图 -->
			<cusSwiper></cusSwiper>
			<!-- tabs -->
			<u-tabs :list="list1" class="sort" :current="current" @change="change"></u-tabs>
			<!-- 排序 -->
			<view class="sort-box">
				<view @click="toSortShop(item)" class="sort-item" v-for="item in synthesisList" :key="item.id"  >
					<view class="img-box">
						<image class="img" :src="item.picture"></image>
					</view>
					<view class="info-box">
						<view class="name">
							{{item.dishName	}}
						</view>
						<view class="score-box">
							<text class="score">{{item.score}}分</text>
							<text class="sale">月售{{item.sales}}</text>
						</view>
						<view class="distance">
							<view class="price">
								起送￥{{item.sendPay}} 配送￥{{item.distribution}}
							</view>
							<view class="time">
								{{item.time}}分钟 | {{item.distance}}m
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		reqSynthesis,
		reqDistance,
		reqSale,
		reqScore,
		reqCategory

	} from '@/common/api.js'
	export default {
		data() {
			return {
				text: 'dsadsadsa',
				list1: [{
						name: '综合排序'
					},
					{
						name: '销量'
					},
					{
						name: '星级'
					},
					{
						name: '距离'
					}
				],
				current: 0,
				wh: 0,
				// 综合
				synthesisList: [],
				// 分类
				categoryList: []
			}
		},

		methods: {
			// 选项卡
			async change(info) {
				// console.log(info);
				this.current = info.index
				if(this.index == 0) {
					const res = await reqSynthesis()
					this.synthesisList = res.data
				}else if (this.current == 1) {
					const res = await reqSale()
					this.synthesisList = res.data
				}else if (this.index == 2) {
					const res = await reqScore()
					this.synthesisList = res.data
				}else {
					const res = await reqDistance()
					this.synthesisList = res.data
				}
			},
			// 分类
			async category() {
				const res = await reqCategory()
				// console.log(res);
				this.categoryList = res.data
			},
			
			// 跳转商家
			toSortShop(item) {
				// console.log(item);
				uni.navigateTo({
					url:`/subpkg/store/store?id=${item.shopId}`
				})
			},
			
			// 跳转分类信息页
			toCateShop(item) {
				uni.navigateTo({
					url:`/subpkg/cate/cate?id=${item.id}`
				})
			}
 		},
		onLoad() {
			this.change(this.current),
			this.category()
		}
		
	}
</script>

<style lang="scss">
	.home-box {
		position: relative;
		
		.content-box {
			background-color: white;
			border-top-left-radius: 20px;
			border-top-right-radius: 20px;
			position: absolute;
			top: 70px;
			width: 100%;
		}

		.notice-box {
			margin: 10px 0;
			padding: 0 10px;
			.notice {
				border-radius: 20px;
			}
		}
	}

	.sort {
		margin-top: 10px;
		padding: 0 2px;
	}
	.sort-box {
		padding-bottom: 80rpx;
	}
	.sort-item {
		margin: 20px 0;
		display: flex;
		height: 70px;
		width: calc(100% - 24px);
		padding: 0 12px;
	}

	.img-box {
		width: 65px;
		height: 65px;
		border-radius: 10px;
		overflow: hidden;
		margin-right: 10px;

		.img {
			width: 100%;
			height: 100%;
		}
	}

	.info-box {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		width: 80%;

		.name {
			font-size: 18px;
		}

		.score-box {
			.score {
				color: #2588FF;
				margin-right: 15px;
			}

			.sale {
				color: #9098A0;
			}
		}

		.distance {
			display: flex;
			justify-content: space-between;
			color: #9098A0;
		}
	}
	.icon-box {
		padding: 5px;
		display: flex;
		justify-content: space-evenly;
		text-align: center;
		
		.img-box {
			width: 48px;
			height: 48px;
			border-radius: 50%;
			overflow: hidden;
			border: 1px solid transparent;
			background-color: aqua;
			margin: 10px 0;
			.img {
				width: 65%;
				height: 65%;
				margin-top: 5px;
			}
		}
		.category {
			font-size: 14px;
		}
	}
	.icon-item {
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>
